package cn.net.shuxing.yifu.common.service;

import cn.net.shuxing.yifu.common.bean.RechargeHistory;
import cn.net.shuxing.yifu.common.constant.PaymentStatus;
import cn.net.shuxing.yifu.common.mapper.RechargeHistoryMapper;
import cn.net.shuxing.yifu.common.util.CommonExample;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class RechargeHistoryService extends HistoryService<RechargeHistory,RechargeHistoryMapper> {


    public List<RechargeHistory> getsByUserId(Integer userId) {
        CommonExample example = new CommonExample(RechargeHistory.class);
        example.equals("userId",userId);
        example.setOrderByClause("create_time DESC");
        return getsByExample(example);
    }

    public List<RechargeHistory> getsByPaymentStatus(PaymentStatus paymentStatus) {
        CommonExample example = new CommonExample(RechargeHistory.class);
//        example.nequals("paymentStatus",paymentStatus);
        example.equals("paymentStatus",paymentStatus);
        return getsByExample(example);
    }

    public List<RechargeHistory> getsAllCompletedByUserId(Integer userId) {
        CommonExample example = new CommonExample(RechargeHistory.class);
        example.equals("userId",userId);
        example.equals("paymentStatus",PaymentStatus.PAID.name());
        example.setOrderByClause("create_time DESC");
        return getsByExample(example);
    }

    public List<RechargeHistory> getsByType(Integer type) {
        CommonExample example = new CommonExample(RechargeHistory.class);
//        example.nequals("paymentStatus",paymentStatus);
        example.equals("type",type);
        example.setOrderByClause("id DESC");
        return getsByExample(example);
    }

    public List<RechargeHistory> getsByPaymentStatusAndType(String status, int type)
    {
        CommonExample example = new CommonExample(RechargeHistory.class);
//        example.nequals("paymentStatus",paymentStatus);
        example.equals("paymentStatus",status);
        example.equals("type",type);
        return getsByExample(example);
    }

    public List<RechargeHistory> getsByUserIdAndPaymentStatus(Integer userId, PaymentStatus status) {
        CommonExample example = new CommonExample(RechargeHistory.class);
//        example.nequals("paymentStatus",paymentStatus);
        example.equals("paymentStatus",status);
        example.equals("userId",userId);
        example.setOrderByClause("id DESC");
        return getsByExample(example);
    }

    public List<RechargeHistory> getsWalletCashHistory(Integer userId, PaymentStatus status,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        CommonExample example = new CommonExample(RechargeHistory.class);
        example.equals("paymentStatus",status);
        example.equals("userId",userId);
        example.setOrderByClause("id DESC");
        return getsByExample(example);
    }
    public RechargeHistory getByPrepayId(String prepayId){
        CommonExample example = new CommonExample(RechargeHistory.class);
        example.equals("prepayId",prepayId);
        RechargeHistory rechargeHistory = getByExampleWithoutComplete(example);
        return rechargeHistory;
    }
}
